<?php
namespace app\home\controller;

use app\home\model\PaymentsModel;
use app\home\model\CommonModel;
use think\Controller;
use think\Request;

class Payments extends Controller{
    public function __construct(Request $request = null)
    {
        $result = $this->_getBid();
        if(!$result){
            $this->success('未登录', 'index/login');
        }
    }
    public function index(){
        $bid = $this->_getBid();
        $field = 'bid,appid,secret,key,mchid';
        $result = PaymentsModel::instance()->paylist($bid,$field);
        // var_dump($result);exit;
        return view('payments/index',['data'=>$result]);
    }


    public function edit(Request $request){
        $id = $request->get('id');
        $result = PaymentsModel::instance()->payonelist($id);
        //var_dump($result);exit;
        return view('payments/edit',['data'=>$result]);
    }
//
//
//
    public function editer(Request $request){

        $data = $request->post();

        $bid =  $data['bid'];
//        $field = 'name,address,phone';
        $result = PaymentsModel::instance()->payeditlist($bid,$data);
        if($result){
            $this->success('修改成功', 'payments/index');
        }else{
            $this->error('修改失败');
        }
    }
}
